from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _
from lib.django import models as mymodels
from media.models import File
from .project import Project
from lib import constants

from .lib import ProjectSubMixin

class QualityControl(ProjectSubMixin, models.Model):
    """质控"""
    project = models.ForeignKey(
        verbose_name=_("项目"),
        to=Project,
        on_delete=models.CASCADE,
    )
    is_confirmed = models.BooleanField(
        verbose_name=_('质控确认'), 
        default=False
    )
    quality_control_cause = models.TextField(
        verbose_name=_('有因质控'), 
        help_text=_('描述缘由'),
        null=True,
        blank=True,
        default=''
    )
    date_of_inspection = models.DateField(
        verbose_name=_('接受检查日期'), 
        null=True, 
        blank=True, 
        default=None
    )
    inspection_feedback = models.TextField(
        verbose_name=_('接受检查反馈主要问题'),
        null=True,
        blank=True,
        default=''
    )
    training_name = models.CharField(
        verbose_name=_('机构办针对项目进行的培训名称'),
        max_length=constants.TITLE_FIELD_LENGTH,
        null=True,
        blank=True,
        default=None,
    )
    date_of_training = models.DateField(
        verbose_name=_('机构办针对项目进行的培训日期'), 
        null=True, 
        blank=True,
        default=None
    )
    promotion_meeting = models.TextField(
        verbose_name=_('机构办针对质控问题展开培训（培训序号）'),
        null=True,
        blank=True,
        default='',
        help_text=_('如有可填写')
    )
    
    class Meta:
        default_permissions = []
        db_table = 'project_quality_control'
        verbose_name = _('质控')
        verbose_name_plural = verbose_name

    @classmethod
    def get_link(cls, project_id, id):
        return reverse("project:quality_control/detail", kwargs={'project_pk': project_id, 'pk': id})

